var Mock = require("mockjs");
const patient = ['Java程序员', '前端工程师', '产品经理', '测试工程师', '运维工程师', 'UI设计师', '大数据工程师', '网络安全工程师', '数据库工程师', '网络工程师', '网络安全工程师']
const patient_new = [
  '虎牙',
  '抖音',
  '斗鱼',
  'B站',
  '京东',
  '淘宝',
  '拼多多',
];
// const variety = ['桂味', '黑叶', '糯米滋', '槐枝', '三月红'];
const conterlist = ['修改账号信息', '修改了天气信息', '修改了用户信息', '进行了账号注销', '注册账号', '完善用户信息', '添加采集配置'];
// const categorieslist = ['灌溉', '除虫', '修建多余树枝', '清除病患体', '注射营养液'];
const Video_quality_settings = ['高码率', '1080p 高清', '720p 高清', '480p 清晰', '360p 流畅', '自动'];
const Interactive_feature_settings = ['弹幕功能', '礼物功能', '投票功能', '抽奖功能', '问答功能', '游戏玩法', '红包功能'];
const live_recording = ['自动录制', '手动录制', '定时录制', '分段录制', '高清录制', '水印设置', '视频剪辑'];
const speed_heightlist = [0.5, 1, 1.5, 2, 2.5, 3];
// const systematic = ['Win10-2021', 'Ubuntu', 'CentOS', 'RedHat', 'Win7-2016', 'Win11-2023'];

const statuslist = ['正常', '异常']
const statuslist2 = ['好评', '差评']
const processorlist = ['intel', 'amd']
const meteorological = ['地面气象观测仪器', '高空气象探测仪器']
var Random = Mock.Random;


const guangdongPlaces = [
  "荔湾区",
  "越秀区",
  "海珠区",
  "天河区",
  "白云区",
  "黄埔区",
  "番禺区",
  "花都区",
  "南沙区",
  "增城区",
  "从化区",
];
const company_list = [
  "广州超越按揭服务有限公司",
  "广州华腾普惠代办按揭服务有限公司",
  "小行家按揭（广州）信息咨询有限公司",
  "广州天河区津滨腾越大厦南塔2103",
];



let users = []
const count = 40
const tokens = []
for (let i = 0; i < count; i++) {
  let blood1 = Math.floor(Math.random() * (80 - 60 + 1)) + 60;
  let blood2 = Math.floor(Math.random() * (150 - 90 + 1)) + 90;
  users.push(
    Mock.mock({
      id: i,
      ID: 'token' + i + Mock.Random.guid().slice(0, 13),
      // name: Mock.Random.cname(),
      title: Mock.Random.cname(),
      addr: '广州市 ' + guangdongPlaces[Math.floor(Math.random() * guangdongPlaces.length)],
      address: '广州市 ' + guangdongPlaces[Math.floor(Math.random() * guangdongPlaces.length)],//随机地址
      company_list1: company_list[Math.floor(Math.random() * company_list.length)],//随机地址
      sex: Mock.Random.integer(0, 1),
      height: Math.floor(Math.random() * (12 - 1 + 1)) + 1,
      weight: Math.floor(Math.random() * (200 - 90 + 1)) + 90,
      temperature: Math.floor(Math.random() * (12 - 1 + 1)) + 1,
      wind: Math.floor(Math.random() * (5000 - 1000 + 1)) + 1000,
      wind1: Math.floor(Math.random() * (215000 - 11000 + 1)) + 1000,
      humidity: Math.floor(Math.random() * (100 - 0 + 1)) + 0,
      Pm2: Math.floor(Math.random() * (250 - 0 + 1)) + 0,
      memory: Math.floor(Math.random() * (30 - 1 + 1)) + 1,
      vCPU: Math.floor(Math.random() * (50 - 1 + 1)) + 1,
      //血压
      bloodpressure: blood1 + '-' + blood2,
      nickName: '@last',
      'url': Random.url('http', Random.first()), // "http://nuysoft.com/ysq"
      'url2': '@url()', // "http://nuysoft.com/ysq"
      phone: /^1[34578]\d{9}$/,//随机电话号码
      'age|11-99': 1,//年龄
      email: '@email',//随机邮箱
      isMale: '@boolean',//随机性别
      createTime: '@datetime',//创建时间
      "county": Random.county(true), // "广东"
      "county2": '@county(广东)', // "广东"
      avatar() {
        //用户头像
        return Mock.Random.image('100×100', Mock.Random.color(), '#757575', 'png', this.nickName)
      },
      // 年龄
      age: Random.integer(20, 50),
      // 随机生成一个 IP 地址
      'IP': Random.ip(), // "112.127.151.37"
      'IP2': '@ip()', // "233.144.17.219"
      // 肝功能
      liverfunction: statuslist[Math.floor(Math.random() * statuslist.length)],
      liverfunction2: statuslist2[Math.floor(Math.random() * statuslist2.length)],
      patient1: patient[Math.floor(Math.random() * patient.length)],
      patient_new1: patient_new[Math.floor(Math.random() * patient_new.length)],
      // variety1: variety[Math.floor(Math.random() * variety.length)],
      conterlist1: conterlist[Math.floor(Math.random() * conterlist.length)],
      Video_quality_settings1: Video_quality_settings[Math.floor(Math.random() * Video_quality_settings.length)],
      Interactive_feature_settings1: Interactive_feature_settings[Math.floor(Math.random() * Interactive_feature_settings.length)],
      live_recording1: live_recording[Math.floor(Math.random() * live_recording.length)],
      speed_heightlist1: speed_heightlist[Math.floor(Math.random() * speed_heightlist.length)],
      // categorieslist1: categorieslist[Math.floor(Math.random() * categorieslist.length)],
      // weather_condition1: weather_condition[Math.floor(Math.random() * weather_condition.length)],
      // systematic1: systematic[Math.floor(Math.random() * systematic.length)],
      processorlist1: processorlist[Math.floor(Math.random() * processorlist.length)],
      meteorological1: meteorological[Math.floor(Math.random() * meteorological.length)],
      guangdongPlaces1: '广东省 ' + guangdongPlaces[Math.floor(Math.random() * guangdongPlaces.length)],
      // 医生建议
      // suggestslist: suggests[Math.floor(Math.random() * suggests.length)],
      // // 血糖
      // bloodsugar: parseFloat((Math.random() * (10 - 1) + 1).toFixed(2)),
      // // 血脂
      // bloodfat: parseFloat((Math.random() * (5 - 1) + 1).toFixed(2)),
      // // 肾功能
      // renalfunction: statuslist[Math.floor(Math.random() * statuslist.length)],
      // // 视力
      // vision: heightlist[Math.floor(Math.random() * heightlist.length)],
      // // 体检时间
      birth: '2023-' + Random.datetime("MM-dd") + '   ' + Random.datetime("HH:mm:ss"),  // 值是指定格式的日期字符串
      // list: {
      //   list1: parseFloat((Math.random() * (100 - 10) + 1).toFixed(2)),
      //   list2: parseFloat((Math.random() * (100 - 10) + 1).toFixed(2)),
      //   list3: parseFloat((Math.random() * (100 - 10) + 1).toFixed(2)),
      //   list4: parseFloat((Math.random() * (100 - 10) + 1).toFixed(2)),
      //   list5: parseFloat((Math.random() * (100 - 10) + 1).toFixed(2)),
      // }
    })
  )
  // console.log(users[1]);
  tokens.push(users[i].ID)
}
let user1 = toObject(tokens, users);
function toObject(names, values) {
  var result = {};
  for (var i = 1; i < names.length; i++)
    result[names[i]] = values[i];
  return result;
}
// console.log(user1);
// let datalist3 = 
function Torisk() {
  let dataid = users.map(v => v.id);
  let datatitle = users.map(v => v.title);
  let databirth = users.map(v => v.birth);
  let list1 = users.map(v => v.list);
  let patient2 = users.map(v => v.patient1);
  // console.log(list2);
  let goodtotol = dataid.map((id, i) => ({
    id,
    name: datatitle[i],
    date: databirth[i],
    list: list1[i],
    patient3: patient2[i],
  }));
  return goodtotol
}
let risklist = Torisk();

export default {
  login: (config) => {
    const { username } = JSON.parse(config.body);
    const token = tokens[username];
    if (!token) {
      return {
        status: 1,
        message: "用户名或密码错误",
      };
    }
    return {
      status: 0,
      token,
    };
  },
  userInfo: (config) => {
    const id = config.body == null ? 0 : config.body
    // console.log(id);
    if (users.filter(v => v.id == id)) {
      var userdata = users.filter(v => v.id == id);
      // console.log(userdata);
      return {
        status: 200,
        userdata
      }
    } else {
      return {
        status: 404,
        message: "信息获取失败"
      }
    }
  },
  getUsers: () => {
    return {
      status: 0,
      users: Object.values(user1),
    };
  },
  getrisk: () => {
    return {
      status: 0,
      users: Object.values(risklist),
    };
  },
  deleteUser: (config) => {
    const { id } = JSON.parse(config.body);
    // console.log(id);
    const token = tokens[id];
    // console.log(tokens[id]);
    // console.log(users);
    if (token) {
      delete user1[token]
      delete tokens[id];
    }
    return {
      status: 0,
    };
  },
  editUser: (config) => {
    const data = JSON.parse(config.body);
    const { id } = data;
    const token = tokens[id];
    if (token) {
      user1[token] = { ...user1[token], ...data };
    }
    return {
      status: 0,
    };
  },
  ValidatUserID: (config) => {
    const userID = config.body;
    const token = tokens[userID];
    if (token) {
      return {
        status: 1,
      };
    } else {
      return {
        status: 0
      };
    }
  },
  addUser: (config) => {
    const data = JSON.parse(config.body);
    const { id } = data;
    tokens[id] = `${id}-token`
    user1[`${id}-token`] = {
      ...user1[`${id}-token`],
      ...data
    }
    return {
      status: 0,
    };
  },
  logout: (_) => {
    return {
      status: 0,
      data: "success",
    };
  },
};
